package com.ruoyi.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.TContent;
import com.ruoyi.business.service.ITContentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 内容管理Controller
 * 
 * @author laoguo
 * @date 2025-08-12
 */
@RestController
@RequestMapping("/business/content")
public class TContentController extends BaseController
{
    @Autowired
    private ITContentService tContentService;

    /**
     * 查询内容管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:content:list')")
    @GetMapping("/list")
    public TableDataInfo list(TContent tContent)
    {
        startPage();
        List<TContent> list = tContentService.selectTContentList(tContent);
        return getDataTable(list);
    }

    /**
     * 导出内容管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:content:export')")
    @Log(title = "内容管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TContent tContent)
    {
        List<TContent> list = tContentService.selectTContentList(tContent);
        ExcelUtil<TContent> util = new ExcelUtil<TContent>(TContent.class);
        util.exportExcel(response, list, "内容管理数据");
    }

    /**
     * 获取内容管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:content:query')")
    @GetMapping(value = "/{contentId}")
    public AjaxResult getInfo(@PathVariable("contentId") Long contentId)
    {
        return success(tContentService.selectTContentByContentId(contentId));
    }

    /**
     * 新增内容管理
     */
    @PreAuthorize("@ss.hasPermi('business:content:add')")
    @Log(title = "内容管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TContent tContent)
    {
        return toAjax(tContentService.insertTContent(tContent));
    }

    /**
     * 修改内容管理
     */
    @PreAuthorize("@ss.hasPermi('business:content:edit')")
    @Log(title = "内容管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TContent tContent)
    {
        return toAjax(tContentService.updateTContent(tContent));
    }

    /**
     * 删除内容管理
     */
    @PreAuthorize("@ss.hasPermi('business:content:remove')")
    @Log(title = "内容管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{contentIds}")
    public AjaxResult remove(@PathVariable Long[] contentIds)
    {
        return toAjax(tContentService.deleteTContentByContentIds(contentIds));
    }
}
